<template>
    <div>
        <van-nav-bar title="个人资料" left-text="返回" left-arrow @click-left="onClickLeft" />

        <van-list v-model="loading" class="shangpin" :finished="finished" finished-text="" @load="onLoad">
            <div v-for="(list, index) in list" :key="index">
                <van-card num="2" :price="list.yuancount" :desc="list.definite" :title="list.proname"
                    :thumb="list.proimg" :origin-price="list.price" />
            </div>

        </van-list>
    </div>
</template>

<script>
import axios from "axios";
export default {
    data() {
        return {
            show: "",
            list: {
                yuancount: "",
            },
            list2: [],
            loading: false,
            finished: false,
        }
    },
    created() {
        this.getList();
        this.getList1();
    },
    methods: {
        onClickLeft() {
            this.$router.push({ path: '/friends' })
        },
        getList() {
            axios({
                url: "/api/user/getUserById",
                method: "GET",
                params: {
                    id: JSON.parse(localStorage.getItem('user')).userId,
                }
            }).then((res) => {
                this.list2 = res.data;
                if (this.list2.userType == 1) {
                    this.vip = "管理员"
                } else if (this.list2.userType == 2) {
                    this.vip = "会员"
                } else if (this.list2.userType == 3) {
                    this.vip = "用户"
                }
                this.getList1();
            });
        },
        getList1() {
            //查询收藏商品数量
            axios({
                url: "/api/user/getUserProject",
                method: "GET",
                params: {
                    ids: this.list2.userOrder,
                },
            }).then((res) => {
                this.list = res.data;
                this.proCount = this.list.length;
                this.list.forEach((v) => {
                    if (this.list2.userType == 2) {
                        v.yuancount = (v.price * 0.95).toFixed(2);
                    } else if (this.list2.userType == 3) {
                        v.yuancount = v.price;
                        v.price=null
                    } else {
                        v.yuancount = (v.price * 0.95).toFixed(2);
                    }
                })
            });
        },
        onLoad() {
            // 异步更新数据
            // setTimeout 仅做示例，真实场景中一般为 ajax 请求
            setTimeout(() => {
                // // 加载状态结束
                // this.loading = false;

                // // 数据全部加载完成
                // if (this.list.length >= 40) {
                this.finished = true;
                // }
            }, 1000);
        },
    },
}
</script>

<style>

</style>